package com.dtagri.fjwlw.api;

import java.util.List;

import com.dtagri.fjwlw.AppContext;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

/**
 * @author wxjn
 * 
 */
public class FJwlwApi {

	/**
	 * 用户登录
	 * 
	 * @param mUserName
	 * @param mPassword
	 * @param mHandler
	 */
	// http://117.27.143.84:80/Tjwlw/api/user_login.action?username=dt&password=123
	public static void login(String mUserName, String mPassword,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.add("username", mUserName);
		params.add("password", mPassword);
		ApiHttpClient.post("user_login.action", params, mHandler);
	}
	/**
	 * 获取服务器适配列表
	 * http://117.27.143.84:80/Tjwlw/api/server_list.action
	 */
	public static void getServerList(AsyncHttpResponseHandler mHandler){
		RequestParams params = new RequestParams();
		params.add("server", "true");
		ApiHttpClient.postServerDT("server_list.action", params, mHandler);
	}
	/**
	 * 获取大区下的传感器
	 * 
	 * @param regionId
	 * @param asyncHttpResponseHandler
	 */
	// http://localhost:8080/Tjwlw/api/equipment_list.action?regionid=142
	public static void companyEquipment(Integer regionId,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.add("regionid", regionId + "");
		ApiHttpClient.post("equipment_list.action", params, mHandler);
	}

	/**
	 * 获取大区下的控制设备
	 * 
	 * @param regionId
	 * @param asyncHttpResponseHandler
	 */
	// http://localhost:8080/Tjwlw/api/equipment_list2.action?regionid=142
	public static void companyEquipment2(Integer regionId,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.add("regionid", regionId + "");
		ApiHttpClient.post("equipment_list2.action", params, mHandler);
	}

	// http://localhost:8080/Tjwlw/api/controlInstruct.action?switch_=0&equipId=37
	/**
	 * 开关设备
	 * 
	 * @param status
	 * @param mHandler
	 */
	public static void equipmentOperate(Integer switch_, Integer ceId,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.add("switch_", switch_ + "");
		params.add("ceId", ceId + "");
		ApiHttpClient.post("controlInstruct.action", params, mHandler);
	}

	// http://localhost:8080/Tjwlw/api/avgHourData_indexContrast.action?equipId=27&companyId=1001&areaIds=55
	/**
	 * 指标对比
	 */
	public static void indexContrast(List<Integer> areaIds, Integer equipSnId,
			Integer companyId, AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		for (Integer integer : areaIds) {
			params.add("areaIds", integer + "");
		}
		params.add("companyId", companyId + "");
		params.add("equipId", equipSnId + "");
		ApiHttpClient
				.post("avgHourData_indexContrast.action", params, mHandler);
	}

	// http://117.27.143.84:80/Tjwlw/api/data_history.action?equipId=27&pageNum=1&pageSize=20&areaId=55&from=2015-6-3 00:00:00&to=2015-6-10 23:59:59
	/**
	 * 历史数据
	 */
	public static void history(Integer equipId, String companyId,
			Integer areaId, Integer pageNum, String from, String to,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.add("pageNum", (pageNum + 1) + "");
		params.add("pageSize", "20");
		params.add("equipId", equipId + "");
		params.add("areaId", areaId + "");
		params.add("from", from);
		params.add("to", to);
		params.add("companyId", companyId);
		ApiHttpClient.get("data_history.action", params, mHandler);
	}

	// http://117.27.143.84:80/Tjwlw/api/realTimeData_list.action?regionid=142
	/**
	 * 实时数据
	 * 
	 * @param regionId
	 * @param mHandler
	 */
	public static void realTimeData(Integer regionId,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.add("regionid", regionId + "");
		ApiHttpClient.get("realTimeData_list.action", params, mHandler);
	}

	// http://localhost:8080/Tjwlw/api/alarmData_list.action?regionid=142&companyId=1001
	/**
	 * 监测报警
	 * 
	 * @param regionId
	 * @param mHandler
	 */
	public static void alarmData(Integer regionId, String companyId,
			AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.add("regionid", regionId + "");
		params.add("companyId", companyId + "");
//		System.out.println("----------params----"+params.toString());
		ApiHttpClient.get("alarmData_list.action", params, mHandler);
	}

	// http://117.27.143.84:80/Tjwlw/api/nvr_list.action?regionId=142
	/**
	 * 获取视频中心
	 * @param regionId
	 * @param mHandler
	 */
	public static void videoList(String username, AsyncHttpResponseHandler mHandler) {
		RequestParams params = new RequestParams();
		params.add("username", username);
		ApiHttpClient.get("nvr_list.action", params, mHandler);
	}
	/**
	 * 获取广告栏图片地址
	 * 
	 */
	public static void getadUrl(AsyncHttpResponseHandler mHandler,String adIp){
		RequestParams params = new RequestParams();
		System.out.println("-----------adIp:"+adIp);
		params.add("serverIp", adIp);
		ApiHttpClient.postServerDT("adurl_list.action", params, mHandler);
	}
	/**
	 * 获取版本信息
	 * 
	 */
	public static void getversionUrl(AsyncHttpResponseHandler mHandler){
		RequestParams params = new RequestParams();
//		System.out.println("-----------adIp:"+adIp);
//		params.add("serverIp", adIp);
		ApiHttpClient.postServerDT("appversion_list.action", params, mHandler);
	}
}
